#ifndef BITWIDGET_H
#define BITWIDGET_H

#include <QTableWidget>
#include <QMainWindow>

class BitWidget : public QMainWindow
{
    Q_OBJECT
public:
    BitWidget(int num = 0);
    virtual ~BitWidget();
    void CustomUI();
    template <typename T> void setNum(T& val)
    {
        for(int i = 0 ; i < tablewidget->columnCount(); i++)
        {
            tablewidget->item(0,i)->setText(QString::number((( val >> i ) & 0x1)));
        }
    }
    quint64 getNum() const
    {
        quint64 retval = 0U;
        for(int i = 0 ; i < num; i++)
        {
            if(tablewidget->columnCount() > i)
            {
                retval |= static_cast<quint64>(((tablewidget->item(0,i)->text().toInt() == 0 ? 0x0 : 0x1) << i));
            }
        }
        return retval;
    }
private slots:
    void catchcellChangedHandler(int,int);
private:
    QTableWidget* tablewidget;
    int num;        //行数
    unsigned long ulCurVal;
};


#endif // BITWIDGET_H
